package com.ruoyi.web.controller.plan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.plan.domain.PlanSubject;
import com.ruoyi.plan.service.IPlanSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * @author MLYNDHG
 * @version 1.0
 * @description 计划科目Controller
 * @date 2023/12/4 16:56
 */
@RestController
@RequestMapping("/plan/subject")
public class PlanSubjectController extends BaseController
{
    @Autowired
    private IPlanSubjectService planSubjectService;

    /**
     * 查询计划科目列表
     */
    @PreAuthorize("@ss.hasPermi('plan:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlanSubject planSubject)
    {
        startPage();
        List<PlanSubject> list = planSubjectService.selectPlanSubjectList(planSubject);
        return getDataTable(list);
    }

    /**
     * 导出计划科目列表
     */
    @PreAuthorize("@ss.hasPermi('plan:subject:export')")
    @Log(title = "计划科目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanSubject planSubject)
    {
        List<PlanSubject> list = planSubjectService.selectPlanSubjectList(planSubject);
        ExcelUtil<PlanSubject> util = new ExcelUtil<PlanSubject>(PlanSubject.class);
        util.exportExcel(response, list, "计划科目数据");
    }

    /**
     * 获取计划科目详细信息
     */
    @PreAuthorize("@ss.hasPermi('plan:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(planSubjectService.selectPlanSubjectById(id));
    }

    /**
     * 新增计划科目
     */
    @PreAuthorize("@ss.hasPermi('plan:subject:add')")
    @Log(title = "计划科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanSubject planSubject)
    {
        return toAjax(planSubjectService.insertPlanSubject(planSubject));
    }

    /**
     * 修改计划科目
     */
    @PreAuthorize("@ss.hasPermi('plan:subject:edit')")
    @Log(title = "计划科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanSubject planSubject)
    {
        return toAjax(planSubjectService.updatePlanSubject(planSubject));
    }

    /**
     * 删除计划科目
     */
    @PreAuthorize("@ss.hasPermi('plan:subject:remove')")
    @Log(title = "计划科目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planSubjectService.deletePlanSubjectByIds(ids));
    }
}